package com.authenticateCenter.event;

import cn.hutool.extra.spring.SpringUtil;
import com.authenticateCenter.mapper.DomainEventMapper;
import com.authenticateCenter.service.IUserService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

import java.util.Map;

/**
 * @author 大忽悠
 * @create 2022/12/22 17:58
 */
public interface DomainEventProcessor {
   @SneakyThrows
   default void processEvent(DomainEvent domainEvent, ObjectMapper objectMapper){
      IUserService userService = SpringUtil.getBean(IUserService.class);
      DomainEventMapper domainEventMapper = SpringUtil.getBean(DomainEventMapper.class);
      Map map = objectMapper.readValue(domainEvent.getEventContent(), Map.class);
      doProcessEvent(domainEvent,map,userService);
      domainEventMapper.deleteById(domainEvent.getId());
   }

   void doProcessEvent(DomainEvent domainEvent, Map map, IUserService userService);
}

